<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="参保人" prop="insuredName">
        <el-input
          v-model="queryParams.insuredName"
          placeholder="请输入参保人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医疗机构" prop="hospitalName">
        <el-select v-model="queryParams.hospitalName" placeholder="请选择医疗机构" clearable>
          <el-option label="北京协和医院" value="北京协和医院" />
          <el-option label="上海瑞金医院" value="上海瑞金医院" />
          <el-option label="广州中山医院" value="广州中山医院" />
          <el-option label="杭州市第一人民医院" value="杭州市第一人民医院" />
          <el-option label="北京朝阳医院" value="北京朝阳医院" />
        </el-select>
      </el-form-item>
      <el-form-item label="时间范围">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="handleQuery"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="20" class="dashboard-header">
      <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
        <div class="stat-card">
          <div class="stat-title">总报销金额</div>
          <div class="stat-value">24,250.00 元</div>
          <div class="stat-footer">本月: 12,750.00 元</div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
        <div class="stat-card">
          <div class="stat-title">报销患者数</div>
          <div class="stat-value">5 人</div>
          <div class="stat-footer">本月: 3 人</div>
        </div>
      </el-col>
<!--      <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">-->
<!--        <div class="stat-card">-->
<!--          <div class="stat-title">门诊报销金额</div>-->
<!--          <div class="stat-value">9,750.00 元</div>-->
<!--          <div class="stat-footer">占比: 40.2%</div>-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">-->
<!--        <div class="stat-card">-->
<!--          <div class="stat-title">住院报销金额</div>-->
<!--          <div class="stat-value">14,500.00 元</div>-->
<!--          <div class="stat-footer">占比: 59.8%</div>-->
<!--        </div>-->
<!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="reimbursementList">
      <el-table-column label="序号" align="center" type="index" width="50" />
      <el-table-column label="参保人" align="center" prop="insuredName" />
      <el-table-column label="身份证号" align="center" prop="idCard" :show-overflow-tooltip="true" />
      <el-table-column label="医疗机构" align="center" prop="hospitalName" />
      <el-table-column label="就诊日期" align="center" prop="visitDate" />
      <el-table-column label="医疗总费用" align="center" prop="totalAmount" />
      <el-table-column label="自付金额" align="center" prop="selfPayAmount" />
      <el-table-column label="报销金额" align="center" prop="reimbursementAmount" />
      <el-table-column label="转账时间" align="center" prop="transferTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleViewDetail(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情对话框 -->
    <el-dialog title="报销详情" :visible.sync="detailOpen" width="700px" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="参保人">{{ detail.insuredName }}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{ detail.idCard }}</el-descriptions-item>
        <el-descriptions-item label="医疗机构">{{ detail.hospitalName }}</el-descriptions-item>
        <el-descriptions-item label="就诊日期">{{ detail.visitDate }}</el-descriptions-item>
        <el-descriptions-item label="医疗总费用">{{ detail.totalAmount }} 元</el-descriptions-item>
        <el-descriptions-item label="自付金额">{{ detail.selfPayAmount }} 元</el-descriptions-item>
        <el-descriptions-item label="报销金额">{{ detail.reimbursementAmount }} 元</el-descriptions-item>
        <el-descriptions-item label="报销账户">
          <el-tag type="primary" v-if="detail.accountType === '1'">个人账户</el-tag>
          <el-tag type="success" v-else-if="detail.accountType === '2'">基金账户</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="转账时间" :span="2">{{ detail.transferTime }}</el-descriptions-item>
        <el-descriptions-item label="诊断信息" :span="2">{{ detail.diagnosis }}</el-descriptions-item>
        <el-descriptions-item label="备注信息" :span="2">{{ detail.remark }}</el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getMedicalunitInfo} from "@/api/medical/medicalunit";
export default {
  name: "MedicalUnit",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 报销转账列表
      reimbursementList: [],
      // 详情对话框
      detailOpen: false,
      // 详情数据
      detail: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        insuredName: undefined,
        hospitalName: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报销列表 */
    async getList() {
      this.loading = true;
      const res = await getMedicalunitInfo();
      console.log(res);
      this.reimbursementList = [];

      this.total = this.reimbursementList.length;
      this.loading = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    /** 查看详情按钮操作 */
    handleViewDetail(row) {
      this.detail = row;
      this.detailOpen = true;
    }
  }
};
</script>

<style scoped>
.dashboard-header {
  margin-bottom: 20px;
}
.stat-card {
  background-color: #fff;
  border-radius: 4px;
  padding: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 15px;
}
.stat-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 10px;
}
.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 10px;
}
.stat-footer {
  font-size: 12px;
  color: #606266;
}
</style>
